{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from draw_func import draw_pie\n",
    "from draw_func import draw_bar\n",
    "from draw_func import draw_line\n",
    "from draw_func import count\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "def upperH(x):\n",
    "    if x=='Very high':\n",
    "        x='Very High'\n",
    "    return x\n",
    "\n",
    "def toNumber(x):\n",
    "    if type(x)==type('str'):\n",
    "        x=x.replace(',','')\n",
    "        x=x.replace('.','')\n",
    "        x=int(x)\n",
    "    elif type(x)==type(123):\n",
    "        ...\n",
    "    elif type(x)==type(1.0) and pd.notnull(x):\n",
    "        x=int(x*1000)\n",
    "    else:\n",
    "        x=-1\n",
    "    return x\n",
    "\n",
    "def silceByYears(data):\n",
    "    data2017=data.loc[data['year']==2017]\n",
    "    data2018=data.loc[data['year']==2018]\n",
    "    data2019=data.loc[data['year']==2019]\n",
    "    data2020=data.loc[data['year']==2020]\n",
    "    data2021=data.loc[data['year']==2021]\n",
    "    data2022=data.loc[data['year']==2022]\n",
    "    return data2017,data2018,data2019,data2020,data2021,data2022"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(r\"QsRank.csv\")\n",
    "\n",
    "# 删去不要的列\n",
    "data=data.drop(columns=['link', 'logo'])\n",
    "\n",
    "# 处理格式不一的列\n",
    "# data=data.fillna(-1)\n",
    "data['faculty_count']=data['faculty_count'].apply(toNumber)\n",
    "data['research_output']=data['research_output'].apply(upperH)\n",
    "data['international_students']=data['international_students'].apply(toNumber)\n",
    "\n",
    "# 按年份分\n",
    "data2017,data2018,data2019,data2020,data2021,data2022=silceByYears(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(data.loc[(data['country']=='China (Mainland)')&(data['year']==2017)])\n",
    "# draw_line(data,'UCL','score','./qs/line')\n",
    "# draw_line(data,'UCL','rank_display','./qs/line')\n",
    "# draw_pie(data2017,'country','./qs/pie','2017')\n",
    "# draw_pie(data2017,'city','./qs/pie','2017')\n",
    "# draw_pie(data2017,'region','./qs/pie','2017')\n",
    "# draw_pie(data,'type','./qs/pie','all')\n",
    "# draw_pie(data,'size','./qs/pie','all')\n",
    "# draw_bar(data2017,'size','./qs/bar','2017')\n",
    "# draw_bar(data2017,'research_output','./qs/bar','2017')\n",
    "# draw_pie(data2017,'research_output','./qs/pie','2017')"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "e5a1b45ef7d6e07b7f3a9fa5fd5d8cd6e8dab5a6dee29f49036f10185b5ccba6"
  },
  "kernelspec": {
   "display_name": "Python 3.8.13 ('38')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
